package com.kczd.jinlan.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.kczd.jinlan.R;
import com.kczd.jinlan.adapter.TabLayoutAdapter;
import com.kczd.jinlan.fragment.PingjiaFragment;
import com.kczd.jinlan.fragment.ShangPingFragment;
import com.kczd.jinlan.fragment.XiangqingFragement;
import com.kczd.jinlan.utils.OrderUtils;

import java.util.ArrayList;
import java.util.List;

public class DetailsFoodActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;

    private List<Fragment> list;
    private String[] titles = {"商品", "详情", "评价"};
    private TabLayoutAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details_food);
        initView();
    }
    private void initView() {
        //实例化
        viewPager = (ViewPager)findViewById(R.id.viewdetails);
        tabLayout = (TabLayout)findViewById(R.id.tablayoutdetails);

        /**
         * 设置tablayout的长度
         */
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                OrderUtils.setIndicator(tabLayout, 15, 15);
            }
        });

        //页面，数据源
        list = new ArrayList<>();
        list.add(new ShangPingFragment());
        list.add(new XiangqingFragement());
        list.add(new PingjiaFragment());
        //ViewPager的适配器this
        adapter = new TabLayoutAdapter(this.getSupportFragmentManager(), list, titles);
        viewPager.setAdapter(adapter);
        //绑定
        tabLayout.setupWithViewPager(viewPager);

    }
}
